package zzz.dubbo.rpc.injvm;

import zzz.dubbo.rpc.service.DemoServiceImpl;
import zzz.dubbo.rpc.service.IDemoService;

import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.extension.ExtensionLoader;
import com.alibaba.dubbo.rpc.Protocol;
import com.alibaba.dubbo.rpc.ProxyFactory;

public class TestCase01 {
    public static void main(String[] args) {
        try {
            run();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static void run() throws Exception {
        // 公共信息
        Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
        ProxyFactory proxy = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
        URL url = URL.valueOf("injvm://127.0.0.1/TestService").addParameter(Constants.INTERFACE_KEY, IDemoService.class.getName());
        
        // 发布服务
        IDemoService sour = new DemoServiceImpl();
        protocol.export(proxy.getInvoker(sour, IDemoService.class, url));
        
        // 获得服务
        IDemoService dest = proxy.getProxy(protocol.refer(IDemoService.class, url));
        
        // 测试服务
        System.out.println(dest.getSize(new String[]{"", "", ""}));
        Object rest = dest.invoke("service", "invoke");
        System.out.println(rest);
        System.out.println(sour.equals(dest));
    }
}
